package ks.app.adidasguro.client;

import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.widgets.events.DrawEvent;
import com.smartgwt.client.widgets.events.DrawHandler;
import com.smartgwt.client.widgets.layout.*;
import com.smartgwt.client.widgets.tree.Tree;
import com.smartgwt.client.widgets.tree.TreeGrid;
import com.smartgwt.client.widgets.tree.TreeGridField;
import com.smartgwt.client.widgets.tree.TreeNode;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.types.TreeModelType;

public class Adidasguro implements EntryPoint {
	public void onModuleLoad() {
		HLayout mainLayout = new HLayout();
		mainLayout.setWidth100();
		mainLayout.setHeight100();

		TreeGrid treeGrid = new TreeGrid();
		treeGrid.setWidth(400);
		treeGrid.setHeight(400);

		TreeGridField field = new TreeGridField("Name", "메뉴 ");
		field.setCanSort(false);

		treeGrid.setFields(field);

		final Tree tree = new Tree();
		tree.setModelType(TreeModelType.PARENT);
		tree.setNameProperty("Name");
		tree.setIdField("EmployeeId");
		tree.setParentIdField("ReportsTo");
		tree.setShowRoot(true);

		menuTreeNode menuAdmin = new menuTreeNode("4", "1", "관리자 업무 ");
		menuTreeNode menuAdminDiscountList = new menuTreeNode("100",
				"4", "입고/할인율 관리 ");
		menuTreeNode menuAdminProductList = new menuTreeNode("110",
				"4", "상품관리 ");
		menuTreeNode menuAdminStockList = new menuTreeNode("120", "4",
				"재고관리 ");
		menuTreeNode menuAdminBarcodeList = new menuTreeNode("130",
				"4", "바코드관리 ");
		menuTreeNode menuAdminBarcodeBatchAdd = new menuTreeNode("140",
				"4", "바코드일괄등록 ");
		menuTreeNode menuAdminStoreList = new menuTreeNode("150", "4",
				"매장관리 ");
		menuTreeNode menuAdminEmployeeList = new menuTreeNode("160",
				"4", "직원관리 ");
		menuTreeNode menuAdminPartnerList = new menuTreeNode("170",
				"4", "거래처관리 ");
		menuTreeNode menuAdminNoticeList = new menuTreeNode("180", "4",
				"공지사항 관리 ");
		menuTreeNode menuAdminBoardAmongStore = new menuTreeNode("190",
				"4", "매장 간 게시판 관리 ");

		menuTreeNode menuSales = new menuTreeNode("0", "1", "통계업무 ");
		menuTreeNode menuSalesList = new menuTreeNode("10", "0",
				"입고 및 판매현황");
		menuTreeNode menuSalesStoreSummery = new menuTreeNode("11",
				"0", "매장 매출 현황 ");

		tree.setData(new TreeNode[] { menuAdmin, menuAdminDiscountList,
				menuAdminProductList, menuAdminStockList, menuAdminBarcodeList,
				menuAdminBarcodeBatchAdd, menuAdminStoreList,
				menuAdminEmployeeList, menuAdminPartnerList,
				menuAdminNoticeList, menuAdminBoardAmongStore, menuSales,
				menuSalesList, menuSalesStoreSummery });

		treeGrid.addDrawHandler(new DrawHandler() {
			public void onDraw(DrawEvent event) {
				tree.openAll();
			}
		});

		treeGrid.setData(tree);
		treeGrid.setAnimateFolders(true);
		treeGrid.setContents("Details");
		treeGrid.setAlign(Alignment.CENTER);
		treeGrid.setOverflow(Overflow.HIDDEN);
		treeGrid.setHeight("70%");
		treeGrid.setCanReparentNodes(false);

		Label leftNavigationLabel = new Label();
		leftNavigationLabel.setShowResizeBar(true);
		leftNavigationLabel.addChild(treeGrid);

		mainLayout.addMember(leftNavigationLabel);

		VLayout vLayout = new VLayout();
		vLayout.setWidth("70%");

		Label listingLabel = new Label();
		listingLabel.setContents("사용법 ");
		listingLabel.setAlign(Alignment.CENTER);
		listingLabel.setOverflow(Overflow.HIDDEN);
		listingLabel.setHeight("30%");
		listingLabel.setShowResizeBar(true);

		Label detailsLabel = new Label();
		detailsLabel.setContents("내용 ");
		detailsLabel.setAlign(Alignment.CENTER);
		detailsLabel.setOverflow(Overflow.HIDDEN);
		detailsLabel.setHeight("70%");

		vLayout.addMember(listingLabel);
		vLayout.addMember(detailsLabel);

		mainLayout.addMember(vLayout);
		mainLayout.draw();
	}

	public static class menuTreeNode extends TreeNode {

		public menuTreeNode(String employeeId, String reportsTo, String name) {
			setEmployeeId(employeeId);
			setReportsTo(reportsTo);
			setName(name);
		}

		public void setEmployeeId(String value) {
			setAttribute("EmployeeId", value);
		}

		public void setReportsTo(String value) {
			setAttribute("ReportsTo", value);
		}

		public void setName(String name) {
			setAttribute("Name", name);
		}
	}
}
